import React,{useMemo} from 'react'
import {useLocation} from 'react-router-dom'
import {Breadcrumb} from 'antd'

export default function MyBreadcrumb() {
  const breadcrumbConfig={
    "/":['系统主页'],
    "/home/user":['系统主页','系统管理','用户管理'],
    "/home/role":['系统主页','系统管理','角色管理'],
    "/home/product/update":['系统主页','商品管理','修改商品']
  }
  let pathName=useLocation().pathname
  
  const breadcrumbTitleAry=useMemo(()=>{
    if(/\w{24}/.test(pathName)){
      pathName=pathName.substring(0,pathName.lastIndexOf("/"))
    }
    const breadcrumbAry=breadcrumbConfig[pathName]
    if(breadcrumbAry){
      return breadcrumbAry
    }else{
      return []
    }
    
  },[pathName])
  console.log(breadcrumbTitleAry);
  return (
    <Breadcrumb>
      {
        breadcrumbTitleAry.map(item=>(<Breadcrumb.Item>{item}</Breadcrumb.Item>))
      }
    </Breadcrumb>  
  )
}
